<!--
 * @Description: http请求-ajax-xhr 
 * @Author: rendc
 * @Date: 2025-11-07 09:58:18
 * @LastEditors: rendc
 * @LastEditTime: 2025-11-07 14:48:00
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>XHR</title>
</head>
<body>
  XHR 
</body>
<script>
  // 创建xhr实例对象
  var xhr = new XMLHttpRequest();
  console.log('🤡 CC - xhr:', xhr);
  // 当前请求的状态
  console.log('🤡 CC - xhr.readyState:', xhr.readyState); // 0
  // 初始化新创建的请求
  xhr.open("post","https://image.baidu.com/");
  console.log('🤡 CC - xhr.readyState:', xhr.readyState); // 1
  // 设置请求头信息 - 发送格式数据,json
  xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
  xhr.setRequestHeader('Authorization', 'xxxxxx');

  
  // 发送请求
  xhr.send();
  console.log('🤡 CC - xhr.readyState:', xhr.readyState); // 2,3,4

</script>
</html>